﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="KRMeta.aspx.cs" Inherits="IMPPFront.Management.KRMeta" %>
<%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<ext:Store ID="KRGStore" runat="server" AutoSave="true" OnBeforeStoreChanged="HandleRefCodeChanges" 
    SkipIdForNewRecords="false" RefreshAfterSaving="Auto" OnRefreshData="KRGStore_Refresh">
        <Reader>
            <ext:JsonReader IDProperty="idRefCodeDetail">
                <Fields>
                    <ext:RecordField Name="idRefCodeDetail" />
                    <ext:RecordField Name="idRefCode" Type="Int" DefaultValue="107" />
                    <ext:RecordField Name="refCodeDetail" DefaultValue="0"/>
                    <ext:RecordField Name="Description" AllowBlank="false" />
                    <ext:RecordField Name="ShortDescription" AllowBlank="false" />
                </Fields>
            </ext:JsonReader>
        </Reader>
        <Listeners>
            <Exception Handler="
                Ext.net.Notification.show({
                    iconCls    : 'icon-exclamation', 
                    html       : e.message, 
                    title      : 'EXCEPTION', 
                    autoScroll : true, 
                    hideDelay  : 5000, 
                    width      : 300, 
                    height     : 200
                });" />
            <BeforeSave Handler="var valid = true; this.each(function(r){if(r.dirty && !r.isValid()){valid=false;}}); return valid;" />
        </Listeners>
    </ext:Store>
    <ext:Store ID="KRGCombo" runat="server">
        <Reader>
            <ext:JsonReader IDProperty="refCodeDetail">
                <Fields>
                    <ext:RecordField Name="idRefCodeDetail" />
                    <ext:RecordField Name="refCodeDetail" />
                    <ext:RecordField Name="Description" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
     <ext:Store ID="KRRStore" runat="server" AutoSave="true" OnBeforeStoreChanged="HandleRefCodeChanges" 
    SkipIdForNewRecords="false" RefreshAfterSaving="Auto" OnRefreshData="KRRStore_Refresh">
        <Reader>
            <ext:JsonReader IDProperty="idRefCodeDetail">
                <Fields>
                    <ext:RecordField Name="idRefCodeDetail" />
                    <ext:RecordField Name="idRefCode" Type="Int" DefaultValue="108" />
                    <ext:RecordField Name="refCodeDetail" DefaultValue="0"/>
                    <ext:RecordField Name="Description" AllowBlank="false" />
                    <ext:RecordField Name="ShortDescription" AllowBlank="false" />
                </Fields>
            </ext:JsonReader>
        </Reader>
        <Listeners>
            <Exception Handler="
                Ext.net.Notification.show({
                    iconCls    : 'icon-exclamation', 
                    html       : e.message, 
                    title      : 'EXCEPTION', 
                    autoScroll : true, 
                    hideDelay  : 5000, 
                    width      : 300, 
                    height     : 200
                });" />
            <BeforeSave Handler="var valid = true; this.each(function(r){if(r.dirty && !r.isValid()){valid=false;}}); return valid;" />
        </Listeners>
    </ext:Store>
    <ext:Store ID="KRRCombo" runat="server">
        <Reader>
            <ext:JsonReader IDProperty="refCodeDetail">
                <Fields>
                    <ext:RecordField Name="idRefCodeDetail" />
                    <ext:RecordField Name="refCodeDetail" />
                    <ext:RecordField Name="Description" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
     <ext:Store ID="KTStore" runat="server" AutoSave="true" OnBeforeStoreChanged="HandleRefCodeChanges" 
    SkipIdForNewRecords="false" RefreshAfterSaving="Auto" OnRefreshData="KTStore_Refresh">
        <Reader>
            <ext:JsonReader IDProperty="idRefCodeDetail">
                <Fields>
                    <ext:RecordField Name="idRefCodeDetail" />
                    <ext:RecordField Name="idRefCode" Type="Int" DefaultValue="109" />
                    <ext:RecordField Name="refCodeDetail" DefaultValue="0"/>
                    <ext:RecordField Name="Description" AllowBlank="false" />
                    <ext:RecordField Name="ShortDescription" AllowBlank="false" />
                </Fields>
            </ext:JsonReader>
        </Reader>
        <Listeners>
            <Exception Handler="
                Ext.net.Notification.show({
                    iconCls    : 'icon-exclamation', 
                    html       : e.message, 
                    title      : 'EXCEPTION', 
                    autoScroll : true, 
                    hideDelay  : 5000, 
                    width      : 300, 
                    height     : 200
                });" />
            <BeforeSave Handler="var valid = true; this.each(function(r){if(r.dirty && !r.isValid()){valid=false;}}); return valid;" />
        </Listeners>
    </ext:Store>
    <ext:Store ID="KTCombo" runat="server">
        <Reader>
            <ext:JsonReader IDProperty="refCodeDetail">
                <Fields>
                    <ext:RecordField Name="idRefCodeDetail" />
                    <ext:RecordField Name="refCodeDetail" />
                    <ext:RecordField Name="Description" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Panel ID="MainPanel" runat="server" Frame="false" Border="false">
        <Items>
            <ext:Image ID="Image1" runat="server" ImageUrl="~/Images/LogoHH.png" Width="192" />
            <ext:Container ID="RootContainer" runat="server" Layout="VBoxLayout" Height="440">
                <LayoutConfig>
                    <ext:VBoxLayoutConfig Align="Stretch" />
                </LayoutConfig>
                <Items>
                <ext:Container ID="FirstRowContainer" runat="server" Layout="HBoxLayout" Flex="1">
                <LayoutConfig>
                    <ext:HBoxLayoutConfig Padding="0 0 5 0" Align="Stretch" />
                </LayoutConfig>
                <Items>
            <ext:GridPanel runat="server" ID="KRGRefPanel" Margins="0 2 0 15" Flex="1" Title="Kernresultaat gebieden" Height="220" AutoScroll="true" StoreID="KRGStore">
                <TopBar>
                    <ext:Toolbar runat="server" ID="KRGToolbar">
                        <Items>
                            <ext:Button runat="server" ID="AddKRGButton" Icon="Add" Text="Referentie">
                                <Listeners>
                                    <Click Handler="#{KRGRefPanel}.insertRecord();" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button ID="DeleteKRGButton" runat="server" Text="Delete" Icon="Exclamation">
                                <Listeners>
                                    <Click Handler="#{KRGRefPanel}.deleteSelected();" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button ID="Button1" runat="server" Text="Save" Icon="Disk">
                                <Listeners>
                                    <Click Handler="#{KRGRefPanel}.save();" />
                                </Listeners>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <ColumnModel runat="server" ID="KRGRefModel">
                    <Columns>
                        <ext:Column Header="Id" DataIndex="idRefCodeDetail" />
                        <ext:Column Header="RefCode" DataIndex="idRefCode" />
                        <ext:Column Header="Omschrijving" DataIndex="Description" >
                            <Editor>
                                <ext:TextField runat="server" ID="KRGDescField" />
                            </Editor>
                        </ext:Column>
                        <ext:Column Header="Korte omschrijving" DataIndex="ShortDescription">
                            <Editor>
                                <ext:TextField runat="server" ID="KRGShortDescField" />
                            </Editor>
                        </ext:Column>
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:RowSelectionModel ID="KRGRefSelectionModel" runat="server" />
                </SelectionModel>
                <LoadMask ShowMask="true" />
                <BottomBar>
                    <ext:PagingToolbar ID="KRGRefPagingTB" runat="server" PageSize="5" />
                </BottomBar>
            </ext:GridPanel>
            <ext:GridPanel runat="server" ID="KRRRefPanel" Margins="0 15 0 2" Flex="1" Title="Kernresultaten" Height="220" AutoScroll="true" StoreID="KRRStore">
                <TopBar>
                    <ext:Toolbar runat="server" ID="KRRRefTB">
                        <Items>
                            <ext:Button runat="server" ID="KRRAddButton" Icon="Add" Text="Cluster">
                                <Listeners>
                                    <Click Handler="#{KRRRefPanel}.insertRecord();" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button ID="KRRDeleteButton" runat="server" Text="Delete" Icon="Exclamation">
                                <Listeners>
                                    <Click Handler="#{KRRRefPanel}.deleteSelected();" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button ID="KRRSaveButton" runat="server" Text="Save" Icon="Disk">
                                <Listeners>
                                    <Click Handler="#{KRRRefPanel}.save();" />
                                </Listeners>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <ColumnModel runat="server" ID="KRRRefModel">
                    <Columns>
                        <ext:Column Header="Id" DataIndex="idRefCodeDetail" />
                        <ext:Column Header="RefCode" DataIndex="idRefCode" />
                        <ext:Column Header="Omschrijving" DataIndex="Description" >
                            <Editor>
                                <ext:TextField runat="server" ID="KRRDescTF" />
                            </Editor>
                        </ext:Column>
                        <ext:Column Header="Korte omschrijving" DataIndex="ShortDescription">
                            <Editor>
                                <ext:TextField runat="server" ID="KRRShortDescTF" />
                            </Editor>
                        </ext:Column>
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:RowSelectionModel ID="KRRRefSM" runat="server" />
                </SelectionModel>
                <LoadMask ShowMask="true" />
                <BottomBar>
                    <ext:PagingToolbar ID="KRRRefPB" runat="server" PageSize="5" />
                </BottomBar>
            </ext:GridPanel>
            </Items>
            </ext:Container>
            <ext:Container ID="SecondRowContainer" runat="server" Layout="HBoxLayout" Flex="1">
                <LayoutConfig>
                    <ext:HBoxLayoutConfig Padding="0 0 5 0" Align="Stretch" />
                </LayoutConfig>
                <Items>
            <ext:GridPanel runat="server" ID="KTRefPanel" Flex="1" Margins="0 15 0 15" Title="Kerntaken" Height="220" AutoScroll="true" StoreID="KTStore">
                <TopBar>
                    <ext:Toolbar runat="server" ID="Toolbar1">
                        <Items>
                            <ext:Button runat="server" ID="Button5" Icon="Add" Text="Taak">
                                <Listeners>
                                    <Click Handler="#{KTRefPanel}.insertRecord();" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button ID="Button6" runat="server" Text="Delete" Icon="Exclamation">
                                <Listeners>
                                    <Click Handler="#{KTRefPanel}.deleteSelected();" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button ID="Button7" runat="server" Text="Save" Icon="Disk">
                                <Listeners>
                                    <Click Handler="#{KTRefPanel}.save();" />
                                </Listeners>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <ColumnModel runat="server" ID="KTRefCM">
                    <Columns>
                        <ext:Column Header="Id" DataIndex="idRefCodeDetail" />
                        <ext:Column Header="RefCode" DataIndex="idRefCode" />
                        <ext:Column Header="Omschrijving" DataIndex="Description" >
                            <Editor>
                                <ext:TextField runat="server" ID="KTDescTF" />
                            </Editor>
                        </ext:Column>
                        <ext:Column Header="Korte omschrijving" DataIndex="ShortDescription">
                            <Editor>
                                <ext:TextField runat="server" ID="KTShortDescTF" />
                            </Editor>
                        </ext:Column>
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:RowSelectionModel ID="KTRefSM" runat="server" />
                </SelectionModel>
                <LoadMask ShowMask="true" />
                <BottomBar>
                    <ext:PagingToolbar ID="KTRefPT" runat="server" PageSize="5" />
                </BottomBar>
            </ext:GridPanel>
            </Items>
            </ext:Container>
            </Items>
            </ext:Container>
            <ext:Container ID="Container1" runat="server" Layout="VBoxLayout" Height="400">
                <LayoutConfig>
                    <ext:VBoxLayoutConfig Align="Stretch" />
                </LayoutConfig>
                <Items>
            <ext:GridPanel runat="server" ID="KRPanel" Margins="0 15 0 15" Title="Kernresultaten"  AutoHeight="true" AutoScroll="true">
                <TopBar>
                    <ext:Toolbar runat="server" ID="KRToolbar">
                        <Items>
                            <ext:Button runat="server" ID="AddTCButton" Icon="Add" Text="Kernresultaat">
                                <Listeners>
                                    <Click Handler="#{KRPanel}.insertRecord();" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button ID="Button2" runat="server" Text="Delete" Icon="Exclamation">
                                <Listeners>
                                    <Click Handler="#{KRPanel}.deleteSelected();" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button ID="Button3" runat="server" Text="Save" Icon="Disk">
                                <Listeners>
                                    <Click Handler="#{KRTCPanel}.save();" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button ID="AddKRG" runat="server" Text="Gebiedreferenties" Icon="ApplicationEdit">
                                <DirectEvents>
                                    <Click OnEvent="ShowKRGWindow" />
                                </DirectEvents>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <Store>
                    <ext:Store ID="KRStore" runat="server" AutoSave="true" OnBeforeStoreChanged="HandleChanges" SkipIdForNewRecords="false"
                                RefreshAfterSaving="None">                                          
                        <Reader>
                            <ext:JsonReader IDProperty="IdKernresultaat">
                                <Fields>
                                    <ext:RecordField Name="IdKernresultaat" />
                                    <ext:RecordField Name="GebiedRefId" AllowBlank="false" />
                                    <ext:RecordField Name="ResultaatRefId" AllowBlank="false" />                                   
                                    <ext:RecordField Name="TaakRefId" AllowBlank="false" />
                                </Fields>
                            </ext:JsonReader>
                        </Reader>
                        <Listeners>
                            <Exception Handler="
                                Ext.net.Notification.show({
                                    iconCls    : 'icon-exclamation', 
                                    html       : e.message, 
                                    title      : 'EXCEPTION', 
                                    autoScroll : true, 
                                    hideDelay  : 5000, 
                                    width      : 300, 
                                    height     : 200
                                });" />
                            <BeforeSave Handler="var valid = true; this.each(function(r){if(r.dirty && !r.isValid()){valid=false;}}); return valid;" />
                        </Listeners>
                    </ext:Store>
                </Store>
                <ColumnModel runat="server" ID="KRModel">
                    <Columns>
                        <ext:Column Header="Id" DataIndex="IdKernresultaat" />
                        <ext:Column Header="Resultaat" DataIndex="ResultaatRefId">
                            <Renderer Fn="resultaatRenderer" />
                            <Editor>
                                <ext:ComboBox ID="ResultaatComboBox" runat="server" Editable="false" DisplayField="Description" ValueField="refCodeDetail"
                                 ForceSelection="true" EmptyText="Selecter een resultaat..." StoreID="KRRCombo" />
                            </Editor>
                        </ext:Column>
                        <ext:Column Header="Gebied" DataIndex="GebiedRefId">
                            <Renderer Fn="gebiedRenderer" />
                            <Editor>
                                <ext:ComboBox ID="GebiedComboBox" runat="server" Editable="false" DisplayField="Description" ValueField="refCodeDetail"
                                 ForceSelection="true" EmptyText="Selecteer een gebied..." StoreID="KRGCombo" />
                            </Editor>
                        </ext:Column>
                        <ext:Column Header="Taak" DataIndex="TaakRefId">
                            <Renderer Fn="taakRenderer" />
                            <Editor>
                                <ext:ComboBox ID="TaakComboBox" runat="server" Editable="false" DisplayField="Description" ValueField="refCodeDetail"
                                 ForceSelection="true" EmptyText="Selecteer een taak..." StoreID="KTCombo" />
                            </Editor>
                        </ext:Column>
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:RowSelectionModel ID="KRSelectionModel" runat="server" />
                </SelectionModel>
                <LoadMask ShowMask="true" />
                <BottomBar>
                    <ext:PagingToolbar ID="KRPagingToolbar" runat="server" PageSize="10" />
                </BottomBar>
            </ext:GridPanel>
            </Items>
            </ext:Container>
        </Items>
    </ext:Panel>
    <ext:Window ID="RefWindow" 
            runat="server" 
            ShowOnLoad="false" Hidden="true"
            Closable="true"
            Height="400"
            Width="300"
            Icon="Application"
            Title="Referenties"
            Padding="5"
            BodyBorder="false">
            <Items>
                <ext:GridPanel runat="server" ID="RefPanel" Margins="0 2 0 15" Flex="1" Title="Kernresultaat gebieden" Height="220" AutoScroll="true" StoreID="KRGStore">
                <TopBar>
                    <ext:Toolbar runat="server" ID="Toolbar2">
                        <Items>
                            <ext:Button runat="server" ID="Button4" Icon="Add" Text="Referentie">
                                <Listeners>
                                    <Click Handler="#{RefPanel}.insertRecord();" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button ID="Button8" runat="server" Text="Delete" Icon="Exclamation">
                                <Listeners>
                                    <Click Handler="#{RefPanel}.deleteSelected();" />
                                </Listeners>
                            </ext:Button>
                            <ext:Button ID="Button9" runat="server" Text="Save" Icon="Disk">
                                <Listeners>
                                    <Click Handler="#{RefPanel}.save();" />
                                </Listeners>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <ColumnModel runat="server" ID="ColumnModel1">
                    <Columns>
                        <ext:Column Header="Id" DataIndex="idRefCodeDetail" />
                        <ext:Column Header="RefCode" DataIndex="idRefCode" />
                        <ext:Column Header="Omschrijving" DataIndex="Description" >
                            <Editor>
                                <ext:TextField runat="server" ID="TextField1" />
                            </Editor>
                        </ext:Column>
                        <ext:Column Header="Korte omschrijving" DataIndex="ShortDescription">
                            <Editor>
                                <ext:TextField runat="server" ID="TextField2" />
                            </Editor>
                        </ext:Column>
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
                </SelectionModel>
                <LoadMask ShowMask="true" />
                <BottomBar>
                    <ext:PagingToolbar ID="PagingToolbar1" runat="server" PageSize="5" />
                </BottomBar>
            </ext:GridPanel>
            </Items>
    </ext:Window>
    <script type="text/javascript">
        var resultaatRenderer = function (value) {
            var r = MainContent_KRRCombo.getById(value);

            if (Ext.isEmpty(r)) {
                return "";
            }

            return r.data.Description;
        };

        var taakRenderer = function (value) {
            var r = MainContent_KTCombo.getById(value);

            if (Ext.isEmpty(r)) {
                return "";
            }

            return r.data.Description;
        };
        var gebiedRenderer = function (value) {
            var r = MainContent_KRGCombo.getById(value);

            if (Ext.isEmpty(r)) {
                return "";
            }

            return r.data.Description;
        };
    </script>
</asp:Content>
